package com.aspose.cells;

import java.util.ArrayList;
import java.util.Iterator;

class zbnw {
   private Shape a;
   private zqy b;
   private zbnu c;
   private zash d;
   private zjx e;
   private zash f;
   private ArrayList g;

   zbnw(Shape var1, zqy var2) {
      this.a = var1;
      this.b = var2;
      this.c = new zbnu(var1.getMsoDrawingType(), 1025, 2560);
   }

   Shape a() {
      return this.a;
   }

   ArrayList b() {
      if (this.g == null) {
         this.g = new ArrayList();
      }

      return this.g;
   }

   void a(zbnw var1, CopyOptions var2) {
      if (var1.d != null) {
         this.c().a(var1.c());
      }

      if (var1.f != null) {
         this.f().a(var1.f);
      }

      if (var1.e != null) {
         this.h().a(var1.h());
      }

      if (var1.c != null) {
         this.i().a(var1.c, var2);
      }

      if (var1.g != null && var1.g.size() != 0) {
         this.g = new ArrayList();
         Iterator var3 = var1.g.iterator();

         while(var3.hasNext()) {
            byte[] var4 = (byte[])var3.next();
            byte[] var5 = new byte[var4.length];
            System.arraycopy(var4, 0, var5, 0, var5.length);
            com.aspose.cells.b.a.a.ze.a(this.g, (Object)var5);
         }
      }

   }

   zash c() {
      if (this.d == null) {
         this.d = new zash(this);
      }

      return this.d;
   }

   zash d() {
      return this.f;
   }

   void e() {
      this.f = null;
   }

   zash f() {
      if (this.f == null) {
         this.f = new zash(this);
      }

      return this.f;
   }

   zqy g() {
      return this.b;
   }

   zjx h() {
      if (this.e == null) {
         this.e = new zjx(this);
      }

      return this.e;
   }

   void a(zjx var1) {
      this.e = var1;
   }

   zbnu i() {
      return this.c;
   }

   int j() {
      int var1 = 0;
      if (this.c != null) {
         var1 += this.i().f() + 8;
      }

      if (!this.a.R()) {
         var1 += this.h().c() + 8;
      }

      if (this.d != null) {
         var1 += this.c().d() + 8;
      }

      if (this.f != null && this.f.b() > 0) {
         var1 += this.f.d() + 8;
      }

      if (this.a.isGroup()) {
         var1 += 24;
      }

      if (this.a.D()) {
         var1 += 8;
      }

      byte[] var3;
      if (this.g != null) {
         for(Iterator var2 = this.g.iterator(); var2.hasNext(); var1 += var3.length) {
            var3 = (byte[])var2.next();
         }
      }

      return var1;
   }

   boolean k() {
      zbjo var1 = this.c().c(49478);
      return var1 != null;
   }

   void a(ShapePathCollection var1) {
      zbjo var2 = this.c().c(49477);
      zbjo var3 = this.c().c(49478);
      if (var3 != null) {
         ShapePathPointCollection var4 = new ShapePathPointCollection();
         byte[] var5;
         int var6;
         int var8;
         if (var2 != null) {
            var5 = (byte[])((byte[])var2.d());
            var6 = com.aspose.cells.b.a.zc.e(var5, 0) & '\uffff';
            boolean var7 = false;
            if ((var5[4] & 255) == 240 && (var5[5] & 255) == 255) {
               var7 = true;
            }

            var8 = 6;

            for(int var9 = 0; var9 < var6; ++var9) {
               if (var7) {
                  var4.a(new ShapePathPoint(Integer.valueOf(com.aspose.cells.b.a.zc.b(var5, var8)), Integer.valueOf(com.aspose.cells.b.a.zc.b(var5, var8 + 2))));
                  var8 += 4;
               } else {
                  var4.a(new ShapePathPoint(com.aspose.cells.b.a.zc.a(var5, var8), com.aspose.cells.b.a.zc.a(var5, var8 + 4)));
                  var8 += 8;
               }
            }
         }

         var5 = (byte[])((byte[])var3.d());
         var6 = com.aspose.cells.b.a.zc.e(var5, 0) & '\uffff';
         int var15 = 6;
         var8 = 0;
         ShapePath var10 = new ShapePath();

         for(int var11 = 0; var11 < var6; ++var11) {
            int var12 = zsk.g((var5[var15 + 1] & 255 & 224) >> 5);
            if (var12 != 7) {
               int var13 = ((var5[var15 + 1] & 255 & 31) << 8) + (var5[var15] & 255);
               int var14;
               ShapeSegmentPath var16;
               label63:
               switch(var12) {
               case 0:
                  var14 = 0;

                  while(true) {
                     if (var14 >= var13) {
                        break label63;
                     }

                     if (var8 + 1 > var4.getCount() - 1) {
                        var1.clear();
                        break label63;
                     }

                     var16 = new ShapeSegmentPath(0);
                     var16.getPoints().a(var4.get(var8++));
                     var16.getPoints().a(var4.get(var8));
                     var10.a(var16);
                     ++var14;
                  }
               case 1:
                  var14 = 0;

                  while(true) {
                     if (var14 >= var13) {
                        break label63;
                     }

                     if (var8 + 3 > var4.getCount() - 1) {
                        var1.clear();
                        break label63;
                     }

                     var16 = new ShapeSegmentPath(1);
                     var16.getPoints().a(var4.get(var8++));
                     var16.getPoints().a(var4.get(var8++));
                     var16.getPoints().a(var4.get(var8++));
                     var16.getPoints().a(var4.get(var8));
                     var10.a(var16);
                     ++var14;
                  }
               case 2:
                  var16 = new ShapeSegmentPath(2);
                  var16.getPoints().a(var4.get(var8));
                  var10.a(var16);
                  break;
               case 3:
                  var16 = new ShapeSegmentPath(3);
                  var10.a(var16);
                  break;
               case 4:
                  var16 = new ShapeSegmentPath(4);
                  var10.a(var16);
                  ++var8;
                  var1.a(var10);
                  var10 = new ShapePath();
                  break;
               case 5:
                  var14 = var5[var15 + 1] & 255 & 31;
                  if (var14 == 10) {
                     var10.b = 4;
                     var10.a = false;
                  } else if (var14 == 11) {
                     var10.c = false;
                     var10.a = false;
                  }
               }
            }

            var15 += 2;
         }

      }
   }

   void l() {
      Geometry var1 = this.a.ag();
      if (this.a.getAutoShapeType() == 0 && var1 != null && var1.a() && ((CustomGeometry)var1).c() != null) {
         ShapePathCollection var2 = ((CustomGeometry)var1).c();
         var2.b();
         this.c().a(320, 0, 0);
         this.c().a(321, 0, 0);
         this.c().a(322, 0, (int)var2.c);
         this.c().a(323, 0, (int)var2.b);
         this.c().a(324, 0, 4);
         ShapePathPointCollection var3 = new ShapePathPointCollection();

         int var6;
         for(int var4 = 0; var4 < var2.getCount(); ++var4) {
            ShapePath var5 = var2.get(var4);

            for(var6 = 0; var6 < var5.getPathSegementList().getCount(); ++var6) {
               ShapeSegmentPath var7 = var5.getPathSegementList().get(var6);
               switch(var7.getType()) {
               case 0:
                  var3.a(var7.getPoints().get(1));
                  break;
               case 1:
                  var3.a(var7.getPoints().get(1));
                  var3.a(var7.getPoints().get(2));
                  var3.a(var7.getPoints().get(3));
                  break;
               case 2:
                  if (var6 == 0) {
                     var3.a(var7.getPoints().get(0));
                  }
               }
            }
         }

         byte[] var13;
         int var14;
         if (var3.getCount() > 0) {
            if (var2.d) {
               var13 = new byte[4 * var3.getCount() + 6];
            } else {
               var13 = new byte[8 * var3.getCount() + 6];
            }

            System.arraycopy(com.aspose.cells.b.a.zc.a(var3.getCount()), 0, var13, 0, 2);
            System.arraycopy(com.aspose.cells.b.a.zc.a(var3.getCount()), 0, var13, 2, 2);
            if (var2.d) {
               var13[4] = -16;
               var13[5] = -1;
            } else {
               System.arraycopy(com.aspose.cells.b.a.zc.a((int)8), 0, var13, 4, 2);
            }

            var14 = 6;

            for(var6 = 0; var6 < var3.getCount(); ++var6) {
               ShapePathPoint var15 = var3.get(var6);
               if (var2.d) {
                  System.arraycopy(com.aspose.cells.b.a.zc.a(var15.getX()), 0, var13, var14, 2);
                  System.arraycopy(com.aspose.cells.b.a.zc.a(var15.getY()), 0, var13, var14 + 2, 2);
                  var14 += 4;
               } else {
                  System.arraycopy(com.aspose.cells.b.a.zc.a(var15.getX()), 0, var13, var14, 4);
                  System.arraycopy(com.aspose.cells.b.a.zc.a(var15.getY()), 0, var13, var14 + 4, 4);
                  var14 += 8;
               }
            }

            this.c().a(49477, 5, var13);
         }

         var13 = new byte[var2.a() + 6];
         var6 = var2.a() / 2;
         System.arraycopy(com.aspose.cells.b.a.zc.a(var6), 0, var13, 0, 2);
         System.arraycopy(com.aspose.cells.b.a.zc.a(var6), 0, var13, 2, 2);
         System.arraycopy(com.aspose.cells.b.a.zc.a((int)2), 0, var13, 4, 2);
         var14 = 6;

         for(int var16 = 0; var16 < var2.getCount(); ++var16) {
            ShapePath var8 = var2.get(var16);

            for(int var9 = 0; var9 < var8.getPathSegementList().getCount(); ++var9) {
               ShapeSegmentPath var10 = var8.getPathSegementList().get(var9);
               byte var11 = 0;
               int var12 = zsk.h(var10.getType());
               switch(var10.getType()) {
               case 0:
                  var11 = 1;
                  break;
               case 1:
                  var11 = 1;
               case 2:
               default:
                  break;
               case 3:
                  var11 = 1;
               }

               System.arraycopy(com.aspose.cells.b.a.zc.a((var12 << 13) + var11), 0, var13, var14, 2);
               var14 += 2;
               if (var10.getType() == 2) {
                  if (var8.b == 4) {
                     var13[var14++] = 0;
                     var13[var14++] = -86;
                  }

                  if (!var8.c) {
                     var13[var14++] = 0;
                     var13[var14++] = -85;
                  }
               }
            }
         }

         this.c().a(49478, 5, var13);
      }

      this.n();
   }

   private void m() {
      this.c().a(384, 447);
      this.c().a(385, 0, 134217793);
   }

   private void n() {
      FillFormat var1 = this.a.B();
      if (var1 != null) {
         this.m();
         MsoFillFormatHelper var2 = this.a.A();
         if (var1.getType() == 0) {
            switch(this.a.getMsoDrawingType()) {
            case 4:
            case 8:
            case 24:
               break;
            default:
               if (this.a.y() != null && this.a.y().c != null) {
                  var2.a(0);
                  var2.setForeColor(this.a.y().c.b.b(this.a.L().n()));
               }
            }
         } else if (var1.getType() == 1) {
            this.c().a(447, 0, 1048576);
         } else if (var1.getType() == 2) {
            var2.a(0);
            var2.setForeColor(var1.getSolidFill().getColor());
            var2.setForeColorTransparency(var1.getSolidFill().getTransparency());
         } else if (var1.getType() == 5) {
            byte[] var3 = MsoFillFormatHelper.f(var1.getPatternFill().getPattern());
            if (var3 == null) {
               return;
            }

            var2.a(1);
            var2.a(var3);
            var2.setForeColor(var1.getPatternFill().getForegroundColor());
            var2.setForeColorTransparency(var1.getPatternFill().getForeTransparency());
            var2.setBackColor(var1.getPatternFill().getBackgroundColor());
            var2.c(var1.getPatternFill().getBackTransparency());
         } else if (var1.getType() == 4) {
            TextureFill var9 = var1.getTextureFill();
            if (var9.getType() == 24) {
               var2.a(3);
            } else {
               var2.a(2);
            }

            if (var9.a() != null) {
               var2.a(var9.a().e());
            }

            var2.setForeColorTransparency(var9.getTransparency());
         } else if (var1.getType() == 3) {
            GradientFill var10 = var1.getGradientFill();
            Workbook var4 = var10.e;
            zanu var5 = new zanu(var10);
            byte[] var6 = var5.b;
            if (var6 != null) {
               var2.c(var6);
            }

            var2.a(4);
            GradientStop var7 = var5.e();
            var2.setForeColor(var7.a.b(var4));
            var2.setForeColorTransparency(var7.getTransparency());
            var7 = var5.f();
            var2.setBackColor(var7.a.b(var4));
            var2.c(var7.getTransparency());
            var2.a((float)var5.c());
            var2.b((float)var5.d() / 100.0F);
            double[] var8 = var5.b();
            if (var8 != null) {
               if (var8[0] != 0.0D) {
                  var2.d((double)((float)var8[0]));
               }

               if (var8[1] != 0.0D) {
                  var2.e((double)((float)var8[1]));
               }

               if (var8[2] != 0.0D) {
                  var2.f((double)((float)var8[2]));
               }

               if (var8[3] != 0.0D) {
                  var2.g((double)((float)var8[3]));
               }
            }

            if (var5.a) {
               var2.e(1073741827);
            }
         }

      }
   }

   int a(byte[] var1, int var2, zbol var3) {
      var1[var2] = 15;
      var1[var2 + 2] = 4;
      var1[var2 + 3] = -16;
      System.arraycopy(com.aspose.cells.b.a.zc.a(this.j()), 0, var1, var2 + 4, 4);
      var2 += 8;
      boolean var4 = false;
      if (this.a.isGroup()) {
         var1[var2] = 1;
         var1[var2 + 2] = 9;
         var1[var2 + 3] = -16;
         var1[var2 + 4] = 16;
         var2 += 8;
         System.arraycopy(com.aspose.cells.b.a.zc.a(var3.a), 0, var1, var2, 4);
         System.arraycopy(com.aspose.cells.b.a.zc.a(var3.c), 0, var1, var2 + 4, 4);
         System.arraycopy(com.aspose.cells.b.a.zc.a(var3.b + var3.a), 0, var1, var2 + 8, 4);
         System.arraycopy(com.aspose.cells.b.a.zc.a(var3.d + var3.c), 0, var1, var2 + 12, 4);
         var2 += 16;
      }

      if (this.c != null) {
         byte var7 = 2;
         int var8 = var7 | this.i().a() << 4;
         System.arraycopy(com.aspose.cells.b.a.zc.a(var8), 0, var1, var2, 2);
         var1[var2 + 2] = 10;
         var1[var2 + 3] = -16;
         var1[var2 + 4] = 8;
         var2 += 8;
         System.arraycopy(com.aspose.cells.b.a.zc.a(this.i().b()), 0, var1, var2, 4);
         System.arraycopy(com.aspose.cells.b.a.zc.a(this.i().c()), 0, var1, var2 + 4, 4);
         var2 += 8;
      }

      if (this.d != null) {
         var2 += this.c().a(this.a, var1, var2, false);
      }

      if (this.f != null && this.f.b() > 0) {
         var2 += this.f.a(this.a, var1, var2, true);
      }

      byte[] var6;
      if (this.g != null) {
         for(Iterator var5 = this.g.iterator(); var5.hasNext(); var2 += var6.length) {
            var6 = (byte[])var5.next();
            System.arraycopy(var6, 0, var1, var2, var6.length);
         }
      }

      return var2;
   }
}
